package com.kd.juhaowan.ui.holder;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.flyjingfish.shapeimageviewlib.ShapeImageView;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.GameModel;
import com.kd.juhaowan.ui.adapter.BaseViewHolder;
import com.kd.juhaowan.ui.listener.OnItemClickListener;
import com.kd.juhaowan.ui.listener.OnItemDianzanListener;
import com.kd.juhaowan.utils.DeviceUtil;
import com.kd.juhaowan.utils.GlideHelper;


import butterknife.BindView;
import butterknife.OnClick;

public class MineGameViewHolder extends BaseViewHolder {



    @BindView(R.id.item_image)
    ShapeImageView imageView;

    @BindView(R.id.item_game_name)
    TextView nameView;

    @BindView(R.id.item_game_info)
    TextView infoView;
    @BindView(R.id.regist_confirm)
    TextView downloadView;





    public MineGameViewHolder(@NonNull View itemView) {
        super(itemView);


    }

    @OnClick(R.id.regist_confirm)
    void onReciveClick(){
        OnItemClickListener listener = getOnItemClickListener();
        if(listener instanceof OnItemDianzanListener){
            ((OnItemDianzanListener) listener).onItemDianzanClick(this,getLayoutPosition());
        }
    }

    @SuppressLint("ResourceType")
    public void setDate(GameModel model){
        GlideHelper.loadGoodsCover(Glide.with(getItemView()),imageView,model.getLogoimage());
        nameView.setText(model.getGame_name());
        infoView.setText(model.getRoles_info());
        if(!TextUtils.isEmpty(model.getDesString())){
            downloadView.setText(model.getDesString());
        }else
        if(DeviceUtil.isInstallApp(getContext(),model.getGame_package_name())){
            downloadView.setText("启动");
        }else{
            downloadView.setText("下载");
        }
    }


}
